
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;


import vista.MainGUI;
import constants.Constants;
import constants.Parameters;
import constants.ReadFromParametersXML;
import controller.Controller;
import controller.NetworkHandler;

/**
 * this is the main class of the program that will launch de app for the users
 * it will connect to the Game Server if it is ready for players and will start and 
 * will add the user to the game
 * @author Jose Luis Garcia && Alvaro Blazquez Checa
 *
 */
public class Main {

	
	public static void main(String[] args) {
		
		try {
			ReadFromParametersXML reader = new ReadFromParametersXML(Constants.PARAMETERS_FILE);
			Parameters.createParameters(reader.getIp(), reader.getPort(), reader.getMaxPlayers(), reader.getMinPlayers(), reader.getMaxMoves());
		} catch (ParserConfigurationException | SAXException | IOException e) {
			Parameters.createParameters(Constants.IP, Constants.PORT, Constants.MAX_PLAYERS, Constants.MIN_PLAYERS, Constants.MAX_MOVES);
		}
		
		Controller controller = new Controller();
		MainGUI gui = new MainGUI(controller);
		NetworkHandler networkHandler = new NetworkHandler(Parameters.getInstance().IP_ADRESS,Parameters.getInstance().PORT,gui);
		controller.setNetworkHandler(networkHandler);
	}
}
